package com.xunji.user.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xunji.user.entity.UserRole;
import com.xunji.user.mapper.UserRoleMapper;
import com.xunji.user.service.UserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserRoleServiceImpl extends ServiceImpl<UserRoleMapper, UserRole> implements UserRoleService {

    @Override
    public void batchSave(List<UserRole> userRoleList) {
        this.saveBatch(userRoleList);
    }

    @Override
    public void deleteByUserId(String userId) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRole::getUserId, userId);
        remove(wrapper);
    }

    @Override
    public List<UserRole> selectByRoleId(List<String> roleIds) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>().in("role_id",roleIds);
        return list(qw);
    }

    @Override
    public List<UserRole> selectByUserId(List<String> userIds) {
        QueryWrapper<UserRole> qw = new QueryWrapper<UserRole>().in("user_id",userIds);
        return list(qw);
    }

    @Override
    public List<UserRole> selectByUserId(String userId) {
        LambdaQueryWrapper<UserRole> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(UserRole::getUserId, userId);
        return list(wrapper);
    }
}
